package com.qiaofang.entity;

import com.qiaofang.common.model.BaseDomain;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.Formula;
import org.springframework.data.annotation.CreatedBy;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 分销
 */
@Data
@Entity
@Table(name = "tm_company")
public class DistributionCompany extends BaseDomain {

    @ApiModelProperty("公司名称")
    @Column(name = "company_name")
    private String companyName;

    @ApiModelProperty("公司类型,对应系统参数表ID")
    @Column(name = "company_type")
    private Long companyType;

    @ApiModelProperty("公司地址")
    @Column(name = "adress")
    private String address;

    @ApiModelProperty("省份")
    @Column(name = "province")
    private Long province;

    @ApiModelProperty("城市")
    @Column(name = "city")
    private Long city;

    @ApiModelProperty("区")
    @Column(name = "zone")
    private Long zone;

    @ApiModelProperty("是否需要佣金 1-是，0-否")
    @Column(name = "commission_flag")
    private String commissionFlag;

    @ApiModelProperty("是否需要短信，1-是，0-否")
    @Column(name = "message_flag")
    private String messageFlag;

    @ApiModelProperty("审核状态：0待审核1审核失败2审核通过")
    @Column(name = "STATUS")
    private String status;

    @ApiModelProperty("公司代码")
    @Column(name = "company_code")
    private String companyCode;

    @ApiModelProperty("负责人姓名")
    @Column(name = "charge_man")
    private String chargeMan;

    @ApiModelProperty("手机号码")
    @Column(name = "phone")
    private String phone;

    @ApiModelProperty("分销首页展示开关 0: 关闭 1: 开启")
    @Column(name = "agency_index_switch")
    private String agencyIndexSwitch;

    @ApiModelProperty("楼盘对外开放开关: 0: 关闭 1: V10")
    @Column(name = "outside_switch")
    private String outsideSwitch;

    @ApiModelProperty("公司简介")
    @Column(name = "introduction")
    private String introduction;

    @ApiModelProperty("")
    @Column(name = "company_uuid")
    private String companyUuid;

    @ApiModelProperty("重复报备开关")
    @Column(name = "repeat_report_switch")
    private String repeatReportSwitch;

    @ApiModelProperty("公司简称")
    @Column(name = "company_abbreviation")
    private String companyAbbreviation;

    /**
     * 所属商户
     */
    @Formula(value = " (select c.id from tm_company c left join tr_company_relation r on c.id = r.dev_company where r.agent_company = id limit 1) ")
    private Long merchantCompanyId;

    /**
     * 渠道经理 parent_id = 0 顶级部门
     */
    @Formula(value = " (select d.principal from tm_department d where d.merchant_id = id and d.del_flag = 0 and d.parent_id = 0) ")
    private Long partnerInfoId;

    @CreatedBy
    @ApiModelProperty("创建人id")
    @Column(name = "create_user_id")
    private Long createUserId;

    @ApiModelProperty("是否删除，0-否，1-是")
    @Column(name = "del_flag")
    private String delFlag;

}
